package guoanmaker.operator.business.controller;

import guoanmaker.operator.business.model.OperatorProvince;
import guoanmaker.operator.business.service.OperatorProvinceServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 *  
 *
 * @author huZhaoyu 
 * @ClassName: OperatorProvinceController
 * @Description: OperatorProvinceController 
 * @date 2017/6/29 上午10:11 
 */
@RestController
@RequestMapping(ApiController.OPERATOR_PROVINCE)
public class OperatorProvinceController {
    private final AjaxJson ajaxJson;
    private final OperatorProvinceServiceInterface operatorProvinceServiceInterface;

    public OperatorProvinceController(AjaxJson ajaxJson, OperatorProvinceServiceInterface operatorProvinceServiceInterface) {
        this.ajaxJson = ajaxJson;
        this.operatorProvinceServiceInterface = operatorProvinceServiceInterface;
    }

    /** 
    * @Title: saveProvince
    * @Description: 新增/修改省份 
    * @param: OperatorProvince   
    * @return AjaxJson    
    * @throws 
    */
    @ApiOperation(value = "保存省份", notes = "新增/修改省份")
    @PostMapping(value = "saveProvince")
    public AjaxJson saveProvince(@RequestBody OperatorProvince operatorProvince) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorProvinceServiceInterface.saveProvince(operatorProvince));
    }

    /** 
     * @Title: deleteProvinceById
     * @Description: 根据Id删除省份
     * @param: String id  
     * @return AjaxJson 
     * @throws 
     */
    @ApiOperation(value = "删除省份", notes = "根据Id删除省份")
    @DeleteMapping(value = "delete/{id}")
    public AjaxJson deleteProvinceById(@PathVariable(value = "id") String id) {
        operatorProvinceServiceInterface.deleteProvinceById(id);
        return ajaxJson.setSuccess(true).setStatus(200).setData("数据删除成功!");
    }

    /**
     * @return OperatorProvince    
     * @Title: getProvinceById 
     * @Description: 根据Id查询省份
     * @param: String id   
     * @throws 
     */
    @ApiOperation(value = "根据Id查询省份", notes = "根据Id查询省份")
    @GetMapping(value = "getProvinceById")
    public AjaxJson getProvinceById(@RequestParam(value = "id") String id) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorProvinceServiceInterface.getProvinceById(id));
    }

    /**
     * @return AjaxJson   
     * @Title: getAllProvince
     * @Description: 查找所有省份 
     * @throws 
     */
    @ApiOperation(value = "查找所有省份", notes = "查找所有省份")
    @GetMapping(value = "getAllProvince")
    public AjaxJson getAllProvince() {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorProvinceServiceInterface.getAllProvince());
    }

    /**
     * @return AjaxJson   
     * @Title: getAllProvinceByPage 
     * @Description: 查询所有省份并分页
     * @param: Integer page 页码
     * @param: Integer size 条数
     * @throws 
     */
    @ApiOperation(value = "分页查询省份", notes = "分页查询省份")
    @GetMapping(value = "getAllProvinceByPage")
    public AjaxJson getAllProvinceByPage(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                           @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorProvinceServiceInterface.getAllProvinceByPage(page, size));
    }


}
